Skip to content

Usg msg reason #275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Usg msg reason #275

wants to merge 14 commits into from

Conversation

nappex
Copy link
Collaborator

@nappex nappex commented Apr 11, 2025

fix #251

@nappex nappex marked this pull request as ready for review April 12, 2025 16:15
Copy link
Owner

@Glutexo Glutexo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pull request! ❤️

Comments marked as ❗️ are blocking. The other ones are more of comments and suggestions.

The two suggested Enum.join(invalid, ", ") occurrences may be DRIED into a function.

  defp join_for_usage_message(args):
    Enum.join(args, ", ")

assert usage_message_printed?(fn -> Onigumo.CLI.main(unquote(combination)) end)
assert usage_message_printed?(
fn -> Onigumo.CLI.main(unquote(combination)) end,
# there is no easy way to do it dynamically
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this sounds fishy.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constant can be amended to contain the expected output.

  @invalid_combinations [
    {["--help", "-C", ".", "downloader"], ["--help"],
    {["downloader", "-h"], ["--help"]},
    {["downloader", "--help"], ["--help"]},
  ]

--help is the only incompatible option though. That means the second element is unnecessary.

We can however omit the comment: there is an easy way to do it, it’s just not necessary.

Suggested change
# there is no easy way to do it dynamically
Suggested change
# there is no easy way to do it dynamically
# The incompatible argument is always --help.

Another thing came to my mind, however. It’s how we always call help to be the the incompatible one and never --working-dir. It makes sense to some extent: a component defines a set of valid switches containing --working-dir and not --help. Thus, it’s --help that’s incompatible. But it may become more complicated if the CLI becomes more convoluted.

Copy link
Owner

@Glutexo Glutexo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pick Request changes for only two reasons:

  • The # there is no easy way to do it dynamically comment doesn’t feel appropriate. There is and easy way. Either do it, change the comment to be more descriptive, or omit it at all.
  • The @invalid_switches extension deserves a preliminary PR that would unblock this one.

assert usage_message_printed?(fn -> Onigumo.CLI.main(unquote(combination)) end)
assert usage_message_printed?(
fn -> Onigumo.CLI.main(unquote(combination)) end,
# there is no easy way to do it dynamically
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constant can be amended to contain the expected output.

  @invalid_combinations [
    {["--help", "-C", ".", "downloader"], ["--help"],
    {["downloader", "-h"], ["--help"]},
    {["downloader", "--help"], ["--help"]},
  ]

--help is the only incompatible option though. That means the second element is unnecessary.

We can however omit the comment: there is an easy way to do it, it’s just not necessary.

Suggested change
# there is no easy way to do it dynamically
Suggested change
# there is no easy way to do it dynamically
# The incompatible argument is always --help.

Another thing came to my mind, however. It’s how we always call help to be the the incompatible one and never --working-dir. It makes sense to some extent: a component defines a set of valid switches containing --working-dir and not --help. Thus, it’s --help that’s incompatible. But it may become more complicated if the CLI becomes more convoluted.

assert usage_message_printed?(
fn -> Onigumo.CLI.main(unquote(combination)) end,
# there is no easy way to do it dynamically
"incompatible OPTIONS --help"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"incompatible OPTIONS --help"
"incompatible OPTIONS #{invalid}"

If the constant contained tuples as imagined above, the string would look like this.

"-c"
["--invalid"],
["-c"],
["-a", "-b"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I am not sure about this. It adds the possibility to test joining for the usage message. But this test should have been there in the first place. Or at least list of invalid switches instead of a single value. I feel it doesn’t belong into this PR.

However, without the list support and this test in place, it is not possible to test the new feature.

Copy link
Collaborator Author

@nappex nappex Apr 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep it maybe in different format, but you have to test a new feature in this PR

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a way how to solve this:

Remove the join both from the executive code and from the tests. That is, only report the first invalid switch. It’s a common fail-fast approach that is not that bad.

Suggested change
["-a", "-b"]

Then, create an issue to report all invalid arguments, not only the first one. For that a PR would add this missing piece.

An alternative approach is to create a new PR before hat. It would change the parametrization to lists and possibly add the new extra item. Merging that PR would unlock this one.

Copy link
Owner

@Glutexo Glutexo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I‘ll approve this once the @invalid_switches matter is resolved. Either of the suggested approaches is fine. See my comment there.

"-c"
["--invalid"],
["-c"],
["-a", "-b"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a way how to solve this:

Remove the join both from the executive code and from the tests. That is, only report the first invalid switch. It’s a common fail-fast approach that is not that bad.

Suggested change
["-a", "-b"]

Then, create an issue to report all invalid arguments, not only the first one. For that a PR would add this missing piece.

An alternative approach is to create a new PR before hat. It would change the parametrization to lists and possibly add the new extra item. Merging that PR would unlock this one.

Comment on lines +12 to +13
["--invalid"],
["-c"],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
["--invalid"],
["-c"],
"--invalid",
"-c"

assert usage_message_printed?(fn -> Onigumo.CLI.main([unquote(switch)]) end)
assert usage_message_printed?(
fn -> Onigumo.CLI.main(unquote(switch)) end,
"invalid OPTIONS #{Enum.join(unquote(switch), ", ")}"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"invalid OPTIONS #{Enum.join(unquote(switch), ", ")}"
"invalid OPTION #{unquote(switch)}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to usage_message to write certain reason of problem to output
2 participants